
(require 'autopair)
(require 'cc-mode)

;;auto-pair
(add-hook 'c-mode-common-hook #'(lambda () (autopair-mode)))

(defun my-c-mode-common-hook()
  (define-key c-mode-base-map (kbd "RET") 'newline-and-indent)
;;  (c-toggle-auto-hungry-state 1)
  (setq c-macro-shrink-window-flag t)
  (setq c-macro-preprocessor "cpp")
  (setq c-macro-cppflags " ")
  (setq c-macro-prompt-flag t)
  (setq hs-minor-mode t)
  (setq abbrev-mode t)
  (setq c-basic-offset 4)
  (setq indent-tabs-mode nil)
  (setq default-tab-width 8)
  (setq tab-stop-list ())
  (local-set-key [(meta j)] 'tabbar-backward)  
  (local-set-key "\C-c\C-u" 'windmove-left)
  (local-set-key "\C-c\C-i" 'windmove-right)
  (local-set-key "\C-c\C-p" 'windmove-up)
  (local-set-key "\C-c\C-n" 'windmove-down) 
  ;;  (local-set-key (kbd "TAB") 'my-indent-or-complete)
)
(add-hook 'c-mode-hook 'my-c-mode-common-hook)
(add-hook 'c++-mode-hook 'my-c-mode-common-hook)
;;自动补全括号等东西

(defun my-indent-or-complete ()
  (interactive)
  (if (looking-at "\\>")
      (hippie-expand nil)
    (indent-for-tab-command)
  )
)

(autoload 'senator-try-expand-semantic "senator")

(setq hippie-expand-try-functions-list
  '(
     senator-try-expand-semantic
     try-expand-dabbrev
     try-expand-dabbrev-visible
     try-expand-dabbrev-all-buffers
     try-expand-dabbrev-from-kill
     try-expand-list
     try-expand-list-all-buffers
     try-expand-line
     try-expand-line-all-buffers
     try-complete-file-name-partially
     try-complete-file-name
     try-expand-whole-kill
   )
)

;;高亮TODO/FIXME/hack等关键词
(add-hook 'c-mode-common-hook
  (lambda ()
    (font-lock-add-keywords nil
      '(("\\<\\(FIXME\\|TODO\\|HACK\\|fixme\\|todo\\|hack\\)" 1
        font-lock-warning-face t)))))

(add-hook 'gdb-mode-hook (lambda ()
     (setq gdb-many-windows t)
     (setq gdb-show-main t)
     ;;(setq gdb-use-separate-io-buffer t)
     ;;(gdb-display-source-buffer)
     ;;(gdb-display-separate-io-buffer)
     ;;(gdb-display-assembler-buffer)
     (setq gud-tooltip-mode t)
))
